﻿using System;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;
using System.Data;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;
using System.Net.NetworkInformation;
using System.Management;
using System.Media;
using System.IO;
using System.Security.Principal;
using CustomControls.Grid;

public partial class Dashboard : System.Web.UI.Page
{
    Microsoft.Practices.EnterpriseLibrary.Data.Database db = DatabaseFactory.CreateDatabase("Application_Data");
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Convert.ToBoolean(Session["sAdministrator"].ToString()) == false)
            {
                this.lnkAlertStatus.Visible = false;
                this.btnClearFailedScheduledTasks.Visible = false;
                this.tblLockedOutAccounts.Visible = false;
                this.btnAddBulletin.Visible = false;
            }     

            if (db.ExecuteScalar(CommandType.Text, "SELECT ConfigValue FROM Config Where ConfigName ='EnableAlerts'").ToString() == "True")
            {
                this.lnkAlertStatus.Text = "Alerts Enabled";
                this.lnkAlertStatus.ForeColor = System.Drawing.Color.Green;
                this.lnkAlertStatus.Font.Bold = false;
            }
            else
            {
                this.lnkAlertStatus.Text = "Alerts Disabled";
                this.lnkAlertStatus.ForeColor = System.Drawing.Color.Red;
                this.lnkAlertStatus.Font.Bold = true;
            }

            Update();
            HideAllDiv();          
        }

        if (this.gvBulletin.Visible == true)
        {
            this.btnViewBulletin.Text = "Hide";
        }
        else
        {
            this.btnViewBulletin.Text = "View";
        }

        if (divAlerts.Visible == true)
        {
            this.btnViewAlerts.Text = "Hide";
        }
        else
        {
            this.btnViewAlerts.Text = "View";
        }

        if (this.divBackupReport.Visible == true)
        {
            this.btnBackupReport.Text = "Hide";
        }
        else
        {
            this.btnBackupReport.Text = "View";
        }

        if (this.divWaitingOrBlockedProcesses.Visible == true)
        {
            this.btnViewWaitingOrBlockedProcesses.Text = "Hide";
        }
        else
        {
            this.btnViewWaitingOrBlockedProcesses.Text = "View";
        }

        if (this.divFailedJobs.Visible == true)
        {
            this.btnViewFailedScheduledTAsks.Text = "Hide";
        }
        else
        {
            this.btnViewFailedScheduledTAsks.Text = "View";
        }

        if (this.divLockedOutSQLAccounts.Visible == true)
        {
            this.btnViewLockedOutSqlAccounts.Text = "Hide";
        }
        else
        {
            this.btnViewLockedOutSqlAccounts.Text = "View";
        }

        if (this.divHighFreeSpace.Visible == true)
        {
            this.btnViewHighFreeSpace.Text = "Hide";
        }
        else
        {
            this.btnViewHighFreeSpace.Text = "View";
        }

        if (this.divLowFreeSpace.Visible == true)
        {
            this.btnViewLowFreeSpace.Text = "Hide";
        }
        else
        {
            this.btnViewLowFreeSpace.Text = "View";
        } 
    }
    protected void Update()
    {            
        this.lnkMonitoredInstanceCount.Text = Convert.ToString(db.ExecuteScalar(CommandType.Text, "SELECT Count(InstanceName) FROM Instance Where DashboardActive = 1").ToString() + " (Monitored)");
        this.lnkNOTMonitoredInstanceCount.Text = Convert.ToString(db.ExecuteScalar(CommandType.Text, "SELECT Count(InstanceName) FROM Instance Where DashboardActive = 0").ToString() + " (NOT Monitored)");
        
        string sqlQuery = "SELECT InstanceName as instance,spid,blocked,databasename,cmd,cpu,physical_io as io,memusage,CASE WHEN (waittime/1000)/3600<10 THEN '0' ELSE '' END + RTRIM((waittime/1000)/3600) + ':' + RIGHT('0'+RTRIM(((waittime/1000) % 3600) / 60),2) + ':' + RIGHT('0'+RTRIM(((waittime/1000) % 3600) % 60),2) AS 'waittime' FROM WaitingOrBlockedProcesses";
        DataSet ds = db.ExecuteDataSet(CommandType.Text, sqlQuery);

        string sqlQuery2 = "SELECT * FROM FailedScheduledTasks";
        DataSet ds2 = db.ExecuteDataSet(CommandType.Text, sqlQuery2);

        string sqlQuery4 = "SELECT InstanceName, LoginName as login, isExpired,isLocked,LockoutTime FROM LOGIN_SQL WHERE isExpired = 1 or isLocked = 1 ORDER BY InstanceName,LoginName";
        DataSet ds4 = db.ExecuteDataSet(CommandType.Text, sqlQuery4);


        string sqlQuery8 = "SELECT AlertID,AlertPriority,AlertInstanceName,AlertName,AlertLastOccurance,AlertCount,AlertStatus FROM Alert WHERE AlertStatus <> 'RESOLVED' ORDER BY AlertLastOccurance DESC ";
        DataSet ds8 = db.ExecuteDataSet(CommandType.Text, sqlQuery8);

        string sqlQuery9 = "SELECT InstanceName,DatabaseName,CASE BackupFrequencyFULL WHEN 0 THEN 'N/A' WHEN NULL THEN 'N/A' ELSE CONVERT(VARCHAR(100),(DATEDIFF(HOUR,LastBackupFULL,getdate())))+' ('+CONVERT(VARCHAR(50),BackupFrequencyFULL)+')' END AS 'HrsSinceLastFULL',CASE BackupFrequencyDIFF WHEN 0 THEN 'N/A' WHEN NULL THEN 'N/A' ELSE CONVERT(VARCHAR(100),(DATEDIFF(HOUR,LastBackupDIFF,getdate())))+' ('+CONVERT(VARCHAR(50),BackupFrequencyDIFF)+')' END AS 'HrsSinceLastDIFF',CASE BackupFrequencyLOG	WHEN 0 THEN 'N/A' WHEN NULL THEN 'N/A' ELSE CONVERT(VARCHAR(100),(DATEDIFF(HOUR,LastBackupLOG,getdate())))+' ('+CONVERT(VARCHAR(50),BackupFrequencyLOG)+')' END AS 'HrsSinceLastLOG' FROM [DATABASE] d with (nolock) WHERE (BackupFrequencyFULL >=1 AND (BackupFrequencyFULL<DATEDIFF(HOUR,LastBackupFULL,getdate()))) OR (BackupFrequencyDIFF >=1 AND (BackupFrequencyDIFF<DATEDIFF(HOUR,LastBackupDIFF,getdate()))) OR (BackupFrequencyLOG >=1 AND (BackupFrequencyLOG<DATEDIFF(HOUR,LastBackupLOG,getdate())))";
        DataSet ds9 = db.ExecuteDataSet(CommandType.Text, sqlQuery9);

        string sqlQuery10 = "SELECT * FROM Bulletin";
        DataSet ds10 = db.ExecuteDataSet(CommandType.Text, sqlQuery10);

        this.gvBulletin.DataSource = ds10;
        this.gvBulletin.DataBind();

        string sqlQueryHighFreeSpace = "SELECT InstanceName, DatabaseName,dbo.FormatNumber(DataSizeMB,'3','i,',0) as SizeMB,dbo.FormatNumber(DataSpaceUsedMB,'3','i,',0) as UsedMB,dbo.FormatNumber(DataSpaceAvailableMB,'3','i,',0) as AvailableMB, DataSpaceAvailablePct as AvailablePct FROM [Database] WHERE DataSpaceAvailableMB is not null and DataSpaceAvailablePct is not null and DataSpaceAvailableMB > 1000 and DataSpaceAvailablePct > 50 and databasename not in('master','model','tempdb','msdb') AND ExceptionHighSpace = 0 ORDER BY DataSpaceAvailableMB DESC";
        DataSet dsHighFreeSpace = db.ExecuteDataSet(CommandType.Text, sqlQueryHighFreeSpace);

        string sqlQueryLowFreeSpace = "SELECT InstanceName, DatabaseName,dbo.FormatNumber(DataSizeMB,'3','i,',0) as SizeMB,dbo.FormatNumber(DataSpaceUsedMB,'3','i,',0) as UsedMB,dbo.FormatNumber(DataSpaceAvailableMB,'3','i,',0) as AvailableMB, DataSpaceAvailablePct as AvailablePct FROM [Database] WHERE DataSpaceAvailableMB is not null and DataSpaceAvailablePct is not null and DataSpaceAvailableMB < 10000 and DataSpaceAvailablePct < 20 and databasename not in('master','model','tempdb','msdb') AND ExceptionLowSpace = 0 ORDER BY DataSpaceAvailablePct";
        DataSet dsLowFreeSpace = db.ExecuteDataSet(CommandType.Text, sqlQueryLowFreeSpace);
        
             
        //Alerts
        this.gvAlerts.DataSource = ds8;
        this.gvAlerts.DataBind();

        int iAlertsUnacknowledged = Convert.ToInt16(db.ExecuteScalar(CommandType.Text, "SELECT Count(*) FROM Alert WHERE AlertStatus = 'OPEN'"));
        int iAlertsAcknowledged = Convert.ToInt16(db.ExecuteScalar(CommandType.Text, "SELECT Count(*) FROM Alert WHERE AlertStatus NOT IN ('RESOLVED','OPEN')"));

        if (gvBulletin.Rows.Count == 0)
        {
            this.gvBulletin.Visible = false;
            this.divBulletin.Visible = false;
            this.btnViewBulletin.Visible = false;
        }
        else
        {
            this.btnViewBulletin.Text = "View";
            this.btnViewBulletin.Visible = true;
        }

        if (gvAlerts.Rows.Count == 0)
        {
            this.gvAlerts.Visible = false;
            this.divAlerts.Visible = false;
            this.btnViewAlerts.Visible = false;
            this.lblAlerts.Font.Bold = false;
            this.lblAlerts.ForeColor = System.Drawing.Color.Black;
            this.imgAlerts.ImageUrl = @"~\Image\green1.gif";
            this.lblAlerts.Text = "No Open Alerts";
        }
        else
        {
            this.btnViewAlerts.Text = "View";
            this.btnViewAlerts.Visible = true;

            if (iAlertsUnacknowledged >= 1)
            {
                this.lblAlerts.Font.Bold = true;
                this.lblAlerts.ForeColor = System.Drawing.Color.Red;
                this.imgAlerts.ImageUrl = @"~\Image\red1.gif";
                this.lblAlerts.Text = "Un-Acknowledged Alerts: " + iAlertsUnacknowledged.ToString() + "  /  Acknowledged Alerts: " + iAlertsAcknowledged.ToString();
            }
            else
            {
                this.lblAlerts.Font.Bold = false;
                this.lblAlerts.ForeColor = System.Drawing.Color.Black;
                this.imgAlerts.ImageUrl = @"~\Image\server_issue.gif";
                this.lblAlerts.Text = "Acknowledged Open Alerts: " + iAlertsAcknowledged.ToString();
            }          
        }

        //Waiting or Blocked Processes
        this.gvWaitingOrBlockedProcesses.DataSource = ds;
        this.gvWaitingOrBlockedProcesses.DataBind();
        if (this.gvWaitingOrBlockedProcesses.Rows.Count == 0)
        {
            this.gvWaitingOrBlockedProcesses.Visible = false;
            this.divWaitingOrBlockedProcesses.Visible = false;
            this.btnViewWaitingOrBlockedProcesses.Visible = false;
            this.lblWaitingOrBlockedProcesses.Font.Bold = false;
            this.lblWaitingOrBlockedProcesses.ForeColor = System.Drawing.Color.Black;
            this.imgBlocks.ImageUrl=@"~\Image\green1.gif";
            this.lblWaitingOrBlockedProcesses.Text = "No Waiting or Blocked Processes";
        }
        else
        {
            this.btnViewWaitingOrBlockedProcesses.Text = "View";
            this.btnViewWaitingOrBlockedProcesses.Visible = true;
            this.btnClearWaitingBlockedProcesses.Visible = false;
            this.lblWaitingOrBlockedProcesses.Font.Bold = true;
            this.lblWaitingOrBlockedProcesses.ForeColor = System.Drawing.Color.Red;
            this.imgBlocks.ImageUrl = @"~\Image\red1.gif";
            this.lblWaitingOrBlockedProcesses.Text = "Waiting or Blocked Processes: " + this.gvWaitingOrBlockedProcesses.Rows.Count.ToString();
        }      
        
        //Failed Jobs
        gvFailedJobs.DataSource = ds2;
        gvFailedJobs.DataBind();
        if (this.gvFailedJobs.Rows.Count == 0)
        {
            this.gvFailedJobs.Visible = false;
            this.divFailedJobs.Visible = false;
            this.btnViewFailedScheduledTAsks.Visible = false;
            this.lblFailedScheduledTasks.Font.Bold = false;
            this.lblFailedScheduledTasks.ForeColor = System.Drawing.Color.Black;
            this.imgFailedTasks.ImageUrl = @"~\Image\green1.gif";
            this.lblFailedScheduledTasks.Text = "No Scheduled Task Errors";
        }
        else
        {
            this.btnViewFailedScheduledTAsks.Text = "View";
            this.btnViewFailedScheduledTAsks.Visible = true;
            this.btnClearFailedScheduledTasks.Visible = false;
            this.lblFailedScheduledTasks.Font.Bold = true;
            this.lblFailedScheduledTasks.ForeColor = System.Drawing.Color.Red;
            this.imgFailedTasks.ImageUrl = @"~\Image\red1.gif";
            this.lblFailedScheduledTasks.Text = "Failed Scheduled Task Count: " + this.gvFailedJobs.Rows.Count.ToString();
        }

        //BackupReport
        this.gvBackupReport1.DataSource = ds9;
        this.gvBackupReport1.DataBind();
        if (this.gvBackupReport1.Rows.Count == 0)
        {
            this.gvBackupReport1.Visible = false;
            this.divBackupReport.Visible = false;
            this.btnBackupReport.Visible = false;
            this.lblBackupReport.Font.Bold = false;
            this.lblBackupReport.ForeColor = System.Drawing.Color.Black;
            this.imgBackup.ImageUrl = @"~\Image\green1.gif";
            this.lblBackupReport.Text = "All Databases have been Backed Up within Defined Frequency";
        }
        else
        {
            this.btnBackupReport.Text = "View";
            this.btnBackupReport.Visible = true;
            this.lblBackupReport.Font.Bold = true;
            this.lblBackupReport.ForeColor = System.Drawing.Color.Red;
            this.imgBackup.ImageUrl = @"~\Image\red1.gif";
            this.lblBackupReport.Text = "Databases Not Backed Up within Defined Frequency: " + gvBackupReport1.Rows.Count.ToString();
        }

        //LowFreeSpace
        this.gvLowFreeSpace.DataSource = dsLowFreeSpace;
        this.gvLowFreeSpace.DataBind();

        if (this.gvLowFreeSpace.Rows.Count == 0)
        {
            this.gvLowFreeSpace.Visible = false;
            this.divLowFreeSpace.Visible = false;
            this.btnViewLowFreeSpace.Visible = false;
            this.lblLowFreeSpace.Font.Bold = false;
            this.lblLowFreeSpace.ForeColor = System.Drawing.Color.Black;
            this.imgLowFreeSpace.ImageUrl = @"~\Image\green1.gif";
            this.lblLowFreeSpace.Text = "No Databases have Low Space Allocation";
        }
        else
        {
            this.btnViewLowFreeSpace.Text = "View";
            this.btnViewLowFreeSpace.Visible = true;
            this.lblLowFreeSpace.Font.Bold = true;
            this.lblLowFreeSpace.ForeColor = System.Drawing.Color.Red;
            this.imgLowFreeSpace.ImageUrl = @"~\Image\red1.gif";
            this.lblLowFreeSpace.Text = "Databases with Low Space Allocation: " + this.gvLowFreeSpace.Rows.Count.ToString();
        } 

        //HighFreeSpace
        this.gvHighFreeSpace.DataSource = dsHighFreeSpace;
        this.gvHighFreeSpace.DataBind();

        if (this.gvHighFreeSpace.Rows.Count == 0)
        {
            this.gvHighFreeSpace.Visible = false;
            this.divHighFreeSpace.Visible = false;
            this.btnViewHighFreeSpace.Visible = false;
            this.lblHighFreeSpace.Font.Bold = false;
            this.lblHighFreeSpace.ForeColor = System.Drawing.Color.Black;
            this.imgHighFreeSpace.ImageUrl = @"~\Image\green1.gif";
            this.lblHighFreeSpace.Text = "No Databases have High Space Allocation";
        }
        else
        {
            this.btnViewHighFreeSpace.Text = "View";
            this.btnViewHighFreeSpace.Visible = true;
            this.lblHighFreeSpace.Font.Bold = true;
            this.lblHighFreeSpace.ForeColor = System.Drawing.Color.Red;
            this.imgHighFreeSpace.ImageUrl = @"~\Image\red1.gif";
            this.lblHighFreeSpace.Text = "Databases with High Space Allocation: " + this.gvHighFreeSpace.Rows.Count.ToString();
        } 

        //Blocked SQL Accounts
        this.gvLockedOutSQLAccounts.DataSource = ds4;
        this.gvLockedOutSQLAccounts.DataBind();

        if (this.gvLockedOutSQLAccounts.Rows.Count == 0)
        {
            this.gvLockedOutSQLAccounts.Visible = false;
            this.divLockedOutSQLAccounts.Visible = false;
            this.btnViewLockedOutSqlAccounts.Visible = false;
            this.lblLockedOutSQLAccounts.Font.Bold = false;
            this.lblLockedOutSQLAccounts.ForeColor = System.Drawing.Color.Black;
            this.imgLockedOutAccounts.ImageUrl = @"~\Image\green1.gif";
            this.lblLockedOutSQLAccounts.Text = "No EXPIRED or LOCKED OUT SQL Logins";
        }
        else
        {
            this.btnViewLockedOutSqlAccounts.Text = "View";
            this.btnViewLockedOutSqlAccounts.Visible = true;
            this.lblLockedOutSQLAccounts.Font.Bold = true;
            this.lblLockedOutSQLAccounts.ForeColor = System.Drawing.Color.Red;
            this.imgLockedOutAccounts.ImageUrl = @"~\Image\red1.gif";
            this.lblLockedOutSQLAccounts.Text = "EXPIRED or LOCKED OUT SQL Logins: " + this.gvLockedOutSQLAccounts.Rows.Count.ToString();
        }        
    }
    protected void btnViewFailedScheduledTAsks_Click(object sender, EventArgs e)
    {
        if (this.gvFailedJobs.Visible == true)
        {
            this.divFailedJobs.Visible = false;
            this.gvFailedJobs.Visible = false;
            this.btnClearFailedScheduledTasks.Visible = false;
            this.btnViewFailedScheduledTAsks.Text = "View";
        }
        else
        {
            this.divFailedJobs.Visible = true;
            this.gvFailedJobs.Visible = true;
            this.btnClearFailedScheduledTasks.Visible = true;
            this.btnViewFailedScheduledTAsks.Text = "Hide";
        }
    }
    protected void btnViewWaitingOrBlockedProcesses_Click(object sender, EventArgs e)
    {
        if (this.gvWaitingOrBlockedProcesses.Visible == true)
        {
            HideAllDiv();
            this.gvWaitingOrBlockedProcesses.Visible = false;
            this.btnClearWaitingBlockedProcesses.Visible = false;
            this.btnViewWaitingOrBlockedProcesses.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divWaitingOrBlockedProcesses.Visible = true;
            this.gvWaitingOrBlockedProcesses.Visible = true;
            this.btnClearWaitingBlockedProcesses.Visible = true;
            this.btnViewWaitingOrBlockedProcesses.Text = "Hide";
        }
    }
    protected void btnBackupReport_Click(object sender, EventArgs e)
    {
        if (this.gvBackupReport1.Visible == true)
        {
            HideAllDiv();
            this.gvBackupReport1.Visible = false;
            this.btnBackupReport.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divBackupReport.Visible = true;
            this.gvBackupReport1.Visible = true;
            this.btnBackupReport.Text = "Hide";
        }
    }
    protected void btnViewLockedOutSqlAccounts_Click(object sender, EventArgs e)
    {
        if (this.gvLockedOutSQLAccounts.Visible == true)
        {
            HideAllDiv();
            this.gvLockedOutSQLAccounts.Visible = false;
            this.btnViewLockedOutSqlAccounts.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divLockedOutSQLAccounts.Visible = true;
            this.gvLockedOutSQLAccounts.Visible = true;
            this.btnViewLockedOutSqlAccounts.Text = "Hide";
        }
    }
    protected void btnClearWaitingBlockedProcesses_Click(object sender, EventArgs e)
    {
        this.btnClearWaitingBlockedProcesses.Visible = false;

        DbCommand dbCommand = db.GetSqlStringCommand("DELETE FROM [WaitingOrBlockedProcesses]");
        db.ExecuteNonQuery(dbCommand);

        Update();
    }
    protected void btnClearFailedScheduledTasks_Click(object sender, EventArgs e)
    {
        this.btnClearFailedScheduledTasks.Visible = false;

        DbCommand dbCommand = db.GetSqlStringCommand("DELETE FROM [FailedScheduledTasks]");
        db.ExecuteNonQuery(dbCommand);

        Update();
    }
    protected void lnkAlertStatus_Click(object sender, EventArgs e)
    {
        if (this.lnkAlertStatus.Text == "Alerts Enabled")
        {
            DbCommand dbCommandConfigValueEnableAlerts = db.GetSqlStringCommand("UPDATE Config SET configValue = 'False' WHERE ConfigName = 'EnableAlerts'");
            db.ExecuteNonQuery(dbCommandConfigValueEnableAlerts);

            this.lnkAlertStatus.Text = "Alerts Disabled";
            this.lnkAlertStatus.ForeColor = System.Drawing.Color.Red;
            this.lnkAlertStatus.Font.Bold = true;
        }
        else
        {
            DbCommand dbCommandConfigValueEnableAlerts = db.GetSqlStringCommand("UPDATE Config SET configValue = 'True' WHERE ConfigName = 'EnableAlerts'");
            db.ExecuteNonQuery(dbCommandConfigValueEnableAlerts);

            this.lnkAlertStatus.Text = "Alerts Enabled";
            this.lnkAlertStatus.ForeColor = System.Drawing.Color.Green;
            this.lnkAlertStatus.Font.Bold = false;
        }        
    }   
    protected void HideAllDiv()
    {
        this.divWaitingOrBlockedProcesses.Visible = false;
        this.divBackupReport.Visible = false;
        this.divFailedJobs.Visible = false;        
        this.divLockedOutSQLAccounts.Visible = false;
        this.divAlerts.Visible = false;
        this.divHighFreeSpace.Visible = false;
        this.divLowFreeSpace.Visible = false; 
        this.btnClearWaitingBlockedProcesses.Visible = false;
        this.btnClearFailedScheduledTasks.Visible = false;        
    } 
    protected void btnViewAlerts_Click(object sender, EventArgs e)
    {
        if (this.gvAlerts.Visible == true)
        {
            HideAllDiv();
            this.gvAlerts.Visible = false;
            this.btnViewAlerts.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divAlerts.Visible = true;
            this.gvAlerts.Visible = true;
            this.btnViewAlerts.Text = "Hide";
        }
    }
    protected void gvAlerts_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            object cellValue = DataBinder.Eval(e.Row.DataItem, "AlertStatus");

            if (cellValue.ToString() == "OPEN")
            {
                e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.backgroundColor='red';";
                e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='';";
                e.Row.Attributes["onClick"] = "location.href='AlertDetail.aspx?AlertID=" + DataBinder.Eval(e.Row.DataItem, "AlertId") + "'";
            }
            else
            {
                e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.backgroundColor='yellow';";
                e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='';";
                e.Row.Attributes["onClick"] = "location.href='AlertDetail.aspx?AlertID=" + DataBinder.Eval(e.Row.DataItem, "AlertId") + "'";
            }     
        }
    }   
    protected void btnAddBulletin_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/AddBulletin.aspx");
    }
    protected void btnViewLowFreeSpace_Click(object sender, EventArgs e)
    {
        if (this.gvLowFreeSpace.Visible == true)
        {
            HideAllDiv();
            this.gvLowFreeSpace.Visible = false;
            this.btnViewLowFreeSpace.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divLowFreeSpace.Visible = true;
            this.gvLowFreeSpace.Visible = true;
            this.btnViewLowFreeSpace.Text = "Hide";
        }
    }
    protected void btnViewHighFreeSpace_Click(object sender, EventArgs e)
    {
        if (this.gvHighFreeSpace.Visible == true)
        {
            HideAllDiv();
            this.gvHighFreeSpace.Visible = false;
            this.btnViewHighFreeSpace.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divHighFreeSpace.Visible = true;
            this.gvHighFreeSpace.Visible = true;
            this.btnViewHighFreeSpace.Text = "Hide";
        }
    }
    protected void btnViewBulletin_Click(object sender, EventArgs e)
    {
        if (this.gvBulletin.Visible == true)
        {
            HideAllDiv();
            this.gvBulletin.Visible = false;
            this.btnViewBulletin.Text = "View";
        }
        else
        {
            HideAllDiv();
            this.divBulletin.Visible = true;
            this.gvBulletin.Visible = true;
            this.btnViewBulletin.Text = "Hide";
        }
    }    
    protected void gvBackupReport_RowDataBound(Object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    object cellValue = DataBinder.Eval(e.Row.DataItem, "HrsSinceLastFULL");
        //
        //    if (cellValue.ToString() == "OPEN")
        //    {
        //        e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';this.style.backgroundColor='red';";
        //        e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='';";
        //        e.Row.Attributes["onClick"] = "location.href='AlertDetail.aspx?AlertID=" + DataBinder.Eval(e.Row.DataItem, "AlertId") + "'";
        //    }
        //}
    }
}